﻿using BotDetector.Core.Detector;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using BotDetector.Core.Model;

namespace BotDetector.Tests.DetectorTests
{
    [TestClass]
    public class BotDetectorTests
    {
        BotDetector.Core.Detector.BotDetector detector = new BotDetector.Core.Detector.BotDetector();
        ResultItemList resultItemList;

        private void Initialize()
        {
            resultItemList = new ResultItemList();
            resultItemList.Add(new ResultItem
            {
                Title = "title",
                Description = "50 dolari reali gratuiti la Pokerstars pe acest link si mai uita-te aici",
                Url = "url"
            });
            resultItemList.Add(new ResultItem
            {
                Title = "title",
                Description = "numai aici ai parte de 50 dolari reali gratuiti la Pokerstars pe acest link",
                Url = "url"
            });
            resultItemList.Add(new ResultItem
            {
                Title = "title",
                Description = "1 2 3 4 50 dolari reali gratuiti la Pokerstars pe acest link 1 2",
                Url = "url"
            });
            resultItemList.Add(new ResultItem
            {
                Title = "50 dolari reali gratuiti la Pokerstars pe acest link",
                Description = "des crip tion",
                Url = "url"
            });
            resultItemList.Phrase = "50 dolari reali gratuiti la Pokerstars pe acest link";
        }

        [TestMethod]
        public void DetectLength_TooShort_True()
        {
            Assert.IsTrue(detector.DetectLength("ana are mere") == BotLength.TooShort);
        }
        [TestMethod]
        public void DetectLength_Short_True()
        {
            Assert.IsTrue(detector.DetectLength("ana are mere si mai are pere") == BotLength.Short);
        }
        [TestMethod]
        public void DetectLength_Short_False()
        {
            Assert.IsFalse(detector.DetectLength("one two three four five six seven eight nine ten eleven") == BotLength.Short);
        }
        [TestMethod]
        public void DetectLength_Medium_True()
        {
            Assert.IsTrue(detector.DetectLength("one two three four five six seven eight nine ten eleven twelve") == BotLength.Medium);
        }
        [TestMethod]
        public void DetectLength_Medium2_True()
        {
            Assert.IsTrue(detector.DetectLength("one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty") == BotLength.Medium);
        }
        [TestMethod]
        public void DetectLength_Long()
        {
            Assert.IsTrue(detector.DetectLength("one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty 21 22 23 24 25 26 27 28") == BotLength.Long);
        }

        [TestMethod]
        public void IsBot_TooShortPhrase_False()
        {
            resultItemList = new ResultItemList();
            resultItemList.Phrase = "doua cuvinte";
            Assert.IsFalse(detector.IsBot(resultItemList));
        }
        [TestMethod]
        public void IsBot_ShortBot_True()
        {
            resultItemList = new ResultItemList();
            resultItemList.Phrase = "ana are mere si mai are pere";
            resultItemList.Add(new ResultItem
            {
                Title = "ana are mere si mai are pere si are cirese",
                Description = "descr",
                Url = "url"
            });
            resultItemList.Add(new ResultItem 
            { 
                Title = "title", 
                Description = "description ana are mere si mai are pere lala", 
                Url = "url" 
            });
            resultItemList.Add(new ResultItem
            {
                Title = "title",
                Description = "ana ana ana are mere si mai are pere ana ana",
                Url = "url"
            });
            Assert.IsTrue(detector.IsBot(resultItemList));
        }
        [TestMethod]
        public void IsBot_ShortBot2_True()
        {
            resultItemList = new ResultItemList();
            resultItemList.Phrase = "Locuri de munca de seriozitate maxima! Oameni foarte multi lucreaza acum cu noi si sunt extrem de multumiti";
            resultItemList.Add(new ResultItem
            {
                Title = "ceva",
                Description = "Locuri de munca cu seriozitate maxima! Oameni multi lucreaza acum cu noi si sunt foarte multumiti",
                Url = "url"
            });
            resultItemList.Add(new ResultItem
            {
                Title = "title",
                Description = "Locuri de munca pentru oameni foarte multi lucreaza acum cu noi si sunt extrem de multumiti",
                Url = "url"
            });
            resultItemList.Add(new ResultItem
            {
                Title = "title",
                Description = "Locuri de munca de seriozitate maxima! Oameni foarte multi lucreaza acum",
                Url = "url"
            });
            resultItemList.Add(new ResultItem
            {
                Title = "title",
                Description = "Locuri de munca de seriozitate mare! Oameni multi lucreaza acum cu noi extrem de multumiti",
                Url = "url"
            });
            resultItemList.Add(new ResultItem
            {
                Title = "title",
                Description = "vino numai la noi pentru locuri de munca de seriozitate mare! Oameni multi lucreaza acum cu noi extrem de multumiti",
                Url = "url"
            });
            Assert.IsTrue(detector.IsBot(resultItemList));
        }
        [TestMethod]
        public void GetFirstTenResults_50elem_10elem()
        {
            resultItemList = new ResultItemList();
            for (int i = 0; i < 50; i++)
            {
                resultItemList.Add(new ResultItem
                {
                    Title = "Titlul" + i,
                    Description = "Description" + i,
                    Url = "URL" + i
                });
            }
            resultItemList = detector.GetFirstTenResults(resultItemList);
            Assert.IsTrue(resultItemList.Count == 10);
        }
        [TestMethod]
        public void CheckIfSong_LyricsSearch_True()
        {
            resultItemList = new ResultItemList();
            resultItemList.Phrase = "i've become so numb become so tires so much more aware i'm becoming this all i want to do is be more like";
            resultItemList.Add(new ResultItem
            {
                Title = "Numb Lyrics-Linkin Park",
                Description = "one thing i don't know why it doesn't even matter how hard you try",
                Url = "www.bestlyrics.org"
            });
            resultItemList.Add(new ResultItem
            {
                Title = "Numb Jay-Z",
                Description = "linkin park song",
                Url = "hhtttp://www.youtube.com/wq0q48q94834"
            });
            resultItemList.Add(new ResultItem
            {
                Title = "Linkin Park Numb lyrics",
                Description = "i've become so numb i can't feel you there, become so tired so much more aware I'm becoming this All I want to do",
                Url = "www.versuri.com"
            });
        }
    }
}

